package com.hanj.gulimall.coupon.controller;

import com.hanj.common.utils.R;
import com.hanj.gulimall.coupon.entity.CouponEntity;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;

/**
 * The type Test controller.
 * RefreshScope:刷新来自配置中心的配置
 *
 * @author hanj.cn @outlook.com
 * @date 2022 /1/15 16:12
 */
@RefreshScope
@RestController
@RequestMapping("/coupon/test")
public class TestController {

    /**
     * Feign connect test.
     *
     * @return the response
     */
    @RequestMapping("/feignConnectTest")
    public R feignConnectTest() {

        CouponEntity couponEntity = new CouponEntity();
        couponEntity.setCouponName("劳斯莱斯5元优惠券");
        return R.ok().put("coupons", Collections.singletonList(couponEntity));
    }

    /**
     * 这三个值将从nacos配置中心的gulimall-coupon.properties读取
     */
    @Value("${nacos-namespace}")
    private String namespace;
    @Value("${whoareyou}")
    private String whoAreYou;
    @Value("${message}")
    private String message;

    /**
     * Gets config from nacos test.
     *
     * @return the config from nacos test
     */
    @RequestMapping("/getConfigFromNacosTest")
    public R getConfigFromNacosTest() {

        return R.ok().put("namespace", namespace).put("whoareyou", whoAreYou).put("message", message);
    }

}
